﻿@using Lib.core;
@using Bll;
@{
    Layout = null;
}

<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=cd1fc22f46e2e763c822e8b6c496b792"></script>

<div id="map_wrapper" style="position: absolute; width: 100%; height: 100%;">
</div>

<script type="text/javascript">
    window.onload = function () {

        var map = new AMap.Map('map_wrapper', {
            zoom: 10, resizeEnable: true
        });
        window.map = map;

        var marker = new AMap.Marker({
            icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png"
        });

        function ChoosePoint(lng, lat) {
            map.panTo([lng, lat]);

            marker.setPosition([lng, lat]);
            marker.setMap(null);
            marker.setMap(map);

            if (window.maplocation) {
                window.maplocation(lng, lat);
            }
            else {
                alert('没有设置地图回调');
            }
        }

        map.on('click', function (e) {
            var lng = e.lnglat.getLng();
            var lat = e.lnglat.getLat();
            ChoosePoint(lng, lat);
        });

        var lng = '@(ViewData["lng"])';
        var lat = '@(ViewData["lat"])';
        if (lng.length > 0 && lat.length > 0) {
            ChoosePoint(parseFloat(lng), parseFloat(lat));
        }

        window.clearMap = function () {
            marker.setMap(null);
        };
    };
</script>
